<?php
require "./lib/browser.php";

$config = require('./lib/config.php');
$browser = Browser::detect();
$qqFlag = $config['QQBROWSER_FLAG'];  // QQ浏览器拦截开关
$redirectBrowsers = ["qqbrowser","mqqbrowser", "ucbrowser", "vivobrowser"];
$mobileBrowsers = ["wechatbrowser", "mqqInternalBrowser"];
$iCode = isset($_GET["i_code"]) && $_GET["i_code"] != ""  ? "?i_code=" . trim($_GET["i_code"]) : "";
$rCode = isset($_GET["r_code"]) && $_GET["r_code"] != ""  ? "?r_code=" . trim($_GET["r_code"]) : "";

// header("Location:./download_ty.html" . $iCode . $rCode);

if (in_array($browser["name"], $redirectBrowsers)) {
  if( $browser["platform"] == "iphone" && ($browser["name"] == "ucbrowser" || $browser["name"] == "mqqbrowser")){
    if ($browser["name"] == "mqqbrowser") {
      if ($qqFlag == '' || $qqFlag == '0') {
        header("Location:./download_ty.html" . $iCode . $rCode);
      } else {
        header("Location:./download_ty.html" . $iCode . $rCode);
      }
    } else {
        header("Location:./download_ty.html" . $iCode . $rCode);
    }
  } elseif ( $browser["platform"] == "android" && $browser["name"] == "mqqbrowser"){
    if ($browser["name"] == "mqqbrowser") {
      if ($qqFlag == '' || $qqFlag == '0') {
        header("Location:./download_ty.html" . $iCode . $rCode);
      } else {
        header("Location:./download_ty.html" . $iCode . $rCode);
      }
    } else {
        header("Location:./download_ty.html" . $iCode . $rCode);
    }
  } elseif ($browser["platform"] == "android" && $browser["name"] == "vivobrowser" )  {
    header("Location:./download_ty.html" . $iCode . $rCode);
  } else {
    header("Location:./download_ty.html" . $iCode . $rCode);
  }
} elseif (in_array($browser["name"], $mobileBrowsers)) {
    header("Location:./download_ty.html" . $iCode . $rCode);
} else {
  header("Location:./download_ty.html" . $iCode . $rCode);
}

return;
